<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<script type="text/javascript">
	function checkForm(){
		const buildId = document.getElementById("buildId").value;
		const num = document.getElementById("num").value;
		const capacity = document.getElementById("capacity").value;
		const status = document.getElementById("status").value;
		if(buildId === "" || num=== "" || capacity === "" || status === ""){
			document.getElementById("error").innerHTML="信息填写不完整！";
			return false;
		}
		return true;
	}
	
	$(document).ready(function(){
		$("ul li:eq(4)").addClass("active");
	});
</script>
<div class="data_list">
		<div class="data_list_title">
		<c:choose>
			<c:when test="${room.id != null }">
				修改宿舍信息
			</c:when>
			<c:otherwise>
				添加宿舍
			</c:otherwise>
		</c:choose>
		</div>
		<form action="room?action=save" method="post" onsubmit="return checkForm()">
			<div class="data_form" >
				<input type="hidden" id="roomId" name="roomId" value="${room.id }"/>
					<table align="center">
						<tr>
							<td><font color="red">*</font>楼栋号：</td>
							<td>
								<select id="buildId" name="buildId" style="width:150px;height: 30px;">
									<c:forEach var="build" items="${buildList}">
										<option value="${build.id }" ${room.buildId==build.id?'selected':'' }>${build.name }</option>
									</c:forEach>
								</select>
							</td>
						</tr>
						<tr>
							<td><font color="red">*</font>宿舍号：</td>
							<td><input type="text" id="num"  name="num" value="${room.num }"  style="margin-top:5px;height:30px;" /></td>
						</tr>
						<tr>
							<td><font color="red">*</font>房间状态：</td>
							<td>
								<select id="capacity" name="capacity" style="width: 150px;">
									<option value="">请选择...</option>
									<option value="二人间" ${room.capacity eq "二人间"?'selected':'' } ${room.capacity eq "二人间"?'selected':'' }>二人间</option>
									<option value="四人间" ${room.capacity eq "四人间"?'selected':'' } ${room.capacity eq "四人间"?'selected':'' }>四人间</option>
									<option value="六人间" ${room.capacity eq "六人间"?'selected':'' } ${room.capacity eq "六人间"?'selected':'' }>六人间</option>
								</select>
							</td>
						</tr>
						<tr>
							<td><font color="red">*</font>房间状态：</td>
							<td>
								<select id="status" name="status" style="width: 150px;">
									<option value="">请选择...</option>
									<option value="未满" ${room.status eq "未满"?'selected':'' }>未满</option>
									<option value="已满" ${room.status eq "已满"?'selected':'' }>已满</option>
								</select>
							</td>
						</tr>
					</table>
					<div align="center">
						<input type="submit" class="btn btn-primary" value="保存"/>
						&nbsp;<button class="btn btn-primary" type="button" onclick="javascript:window.location='room'">返回</button>
					</div>
					<div align="center">
						<font id="error" color="red">${error }</font>
					</div>
			</div>
		</form>
</div>